package shinesend.com.cn.valaanimtordemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * Created by MyPC on 2016/11/10.
 */
public class InterpolatorActivity extends Activity {
    CheckBox c_x, c_y;
    LinearLayout lny_menu;
    ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interpolator);
        lny_menu = (LinearLayout) findViewById(R.id.lny_menu);
        c_x = (CheckBox) findViewById(R.id.x_interpolate);
        c_y = (CheckBox) findViewById(R.id.y_interpolate);
        iv = (ImageView) findViewById(R.id.ball);
    }
    public void pure(View view) {


        /* 创建单纯的平移动画 */
        // x 方向平移
        float finalX = getResources().getDisplayMetrics().widthPixels - iv.getWidth();
        float finalY = lny_menu.getY() - iv.getHeight();


        Animation xAnimation = new TranslateAnimation(0.0f, finalX, .0f, .0f);
        // y 方向平移
        Animation yAnimation = new TranslateAnimation(.0f, .0f, 0.0f, finalY);

        if (c_x.isChecked()) {
            xAnimation.setInterpolator(new DecelerateInterpolator(1));
        }
        if (c_y.isChecked()) {
//            yAnimation.setInterpolator(new BounceInterpolator());
            xAnimation.setInterpolator(new DecelerateInterpolator(0.2f));
        }

        /* 动画集合;*/
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(xAnimation);
        set.addAnimation(yAnimation);

        set.setDuration(1000);
        set.setFillAfter(true);

        iv.startAnimation(set);
    }

    public void cancel(View view) {
        iv.clearAnimation();
    }

}
